/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package peggame;

import java.util.ArrayList;

/**
 *
 * @author zach
 */
public class Instance {
    private Move lastmove;
    private Instance parent;
    private pegmanager board;

    public ArrayList<Integer> openX=new ArrayList<Integer>();
    public ArrayList<Integer> openY=new ArrayList<Integer>();

    public Instance(pegmanager board){
        this.board=new pegmanager(board.getBoard(),board.getIndexvalues(),board.startx,board.starty,board.endx,board.endy);
        lastmove=null;
        parent=null;
    }

    public Instance(Move lastmove, Instance parent, pegmanager board) {
        this.lastmove=lastmove;
        this.parent = parent;
        this.board=new pegmanager(board.getBoard(),board.getIndexvalues(),board.startx,board.starty,board.endx,board.endy);
        Jump(lastmove);
    }
    public int getOffset(int y1,int y2){
        return board.getOffset(y1, y2)+1;
    }

    public Move getLastmove() {
        return lastmove;
    }

    public pegmanager getBoard() {
        return board;
    }

    public Instance getParent() {
        return parent;
    }


    public String toString(){
        if(parent!=null)
            return parent.toString()+lastmove.toString()+"\n";
        else
            return "";
    }
    public void openings(){
        for(int y=0;y<board.getBoard().length;y++){
            for(int x=0;x<board.getBoard()[y].length;x++){
                if(board.getBoard()[y][x]==pegmanager.unvisited_path
                        ||board.getBoard()[y][x]>=pegmanager.path_with_unvisted_parts){
                    openX.add(x);
                    openY.add(y);
                    
                }
            }
        }
    }

    public void Jump(Move move){
        board.Jump(move);
    }
    @Override
    public int hashCode() {
        return board.hashCode();
    }
    public String print(){
        String out="";
        for(int i=0;i<board.getBoard().length;i++){
            
                for(int q=0;q<getOffset(board.getBoard().length/2,i);q++){
                    out+=" ";
                }
            
            for(int y=0;y<board.getBoard()[i].length;y++){
                out+=board.getBoard()[i][y];

            }
            out+="\n";
        }
        return out;
    }
}
